<?php
namespace backend\controllers;

/**
 * 帮助中心
 *
 * @author huipeng.teng@liketry.com
 */
class HelpCenterController extends MyController {
    
  /*public function actions() {
        return [
            'upload' => [
                'class' => 'kucha\ueditor\UEditorAction',
                'config' => [
                    'imageUrlPrefix' => \Yii::getAlias('@static'), //图片访问路径前缀
                    'imagePathFormat' => \Yii::$app->params['upfile'].'/{yyyy}{mm}{dd}/{time}{rand:6}', //上传保存路径
                ],
            ], 
        ];
    } */

    /**
     * 列表
     */
    public function actionList() {
        $helpCenter = new \backend\models\HelpCenter();

        $dataProvider = $helpCenter->search();

        return $this->render('list', [
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * 添加
     */
    public function actionAdd() {
        if(\Yii::$app->request->isPost) {
            \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            $post = \Yii::$app->request->post('HelpCenter');

            $helpCenter = new \backend\models\HelpCenter();
            $return = $helpCenter->addRow($post['title'], $post['content'], intval($post['is_show']));

            return $return;
        }

        $model = new \common\models\HelpCenter();

        return $this->render('add', ['model' => $model]);
    }

    /**
     * 修改
     */
    public function actionUpdate() {
        if(\Yii::$app->request->isPost) {
            \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            $post = \Yii::$app->request->post('HelpCenter');

            $helpCenter = new \backend\models\HelpCenter();
            $return = $helpCenter->updateRow($post['help_center_id'], $post['title'], $post['content'], intval($post['is_show']));

            return $return;
        }

        $id = intval(\Yii::$app->request->get('id'));

        $model = \common\models\HelpCenter::findOne($id);

        if(empty($model)) {
            throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
        }

        return $this->render('update', ['model' => $model]);
    }
}
